#include <iostream>

using namespace std;

int main(void) {


	//C++ muistinvaraus alkaa
	
	int max = 10;
	int** t = new int*[max]; 

	cout << "C++ muistinvarausarvot: "<<endl;
	for (int i = 0; i<max;i++) 
	{
		t[i] = new int;
		*t[i] = i;
		cout << "C++: " << t[i] << " " << *t[i] << endl;
	}
	cout << "C++: " << endl << "C++: " << endl;

	for (int i=0; i<max; i++)
	{
	cout << "C++: " << "Poistetaan osoite: " << t[i] << " sisalto: " << *t[i];
	delete t[i];
	cout << " -> Tyhja sisalto: "  << *t[i] << endl;
	}
	cout << "C++: " << endl << "C++: " << "Poistetaan taulu: " << t << endl;
	cout << "C++: " << "Jonka sisalto on: " << endl;
	for (int i=0;i<max;i++) 
	{
		cout << "C++: " << "Paikka: " << i << " Sisalto: " << t[i] << endl;
	}
	delete[] t;
	cout << "C++: " << endl << "C++: " << "Tyhjan sisalto: " << t << endl;
	for (int i=0;i<max;i++) 
	{
		cout << "C++: " << "Paikka: " << i << " Sisalto: " << t[i] << endl;
	}
	//C++ muistinvaraus loppuu

	//C muistinvaraus alkaa
	
	int max_c = 10;
	int** t_c = NULL;
	t_c = (int **)malloc(max_c*sizeof(int*));

	if (t_c == NULL) { exit; }

	cout << endl << "C Muistinvarausarvot: " << endl;
	for (int i = 0; i<max_c;i++) 
	{
		t_c[i] = (int *)malloc(sizeof(int));
		*t_c[i] = i;
		cout << t_c[i] << " " << *t_c[i] << endl;
	}

	cout << endl << endl;

	for (int i=0; i<max; i++)
	{
	cout << "Poistetaan osoite: " << t_c[i] << " sisalto: " << *t_c[i];
	free(t_c[i]);
	cout << " -> Tyhja sisalto: "  << *t_c[i] << endl;
	}
	cout << endl << "Poistetaan taulu: " << t_c << endl;
	cout << "Jonka sisalto on: " << endl;
	for (int i=0;i<max;i++) 
	{
		cout << "Paikka: " << i << " Sisalto: " << t_c[i] << endl;
	}
	free(t_c);
	cout << endl << "Tyhjan sisalto: " << t_c << endl;
	for (int i=0;i<max;i++) 
	{
		cout << "Paikka: " << i << " Sisalto: " << t_c[i] << endl;
	}
	//C muistinvaraus loppuu
}